package com.dragon.flow.web.resource.bpmn;

import cn.hutool.json.JSONObject;
import com.dragon.flow.web.resource.BaseResource;
import com.dragon.tools.common.ReturnCode;
import com.dragon.tools.utils.FastJsonUtils;
import com.dragon.tools.vo.ReturnVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @title:
 * @author: bruce.liu
 * @since: 2024/4/16 0:06
 */
@Slf4j
@Api(value = "流程对接表单api")
@RestController
@RequestMapping("/flow/form/show")
public class BpmnFormResource extends BaseResource {

    /**
     * 保存
     *
     * @param formItemShow
     * @return
     */
    @ApiOperation("保存表单的设置信息")
    @PostMapping(value = "/saveOne", produces = "application/json")
    public ReturnVo<String> saveOne(@RequestBody JSONObject formItemShow) {
        ReturnVo<String> returnVo = new ReturnVo<>(ReturnCode.FAIL, "保存失败");
        try {
            //TODO 保存数据到自己的表中
            returnVo.setMsg("保存成功！");
            returnVo.setCode(ReturnCode.SUCCESS);
        } catch (Exception e) {
            returnVo.setMsg("保存异常，原因：" + e.getMessage());
            e.printStackTrace();
        }
        return returnVo;
    }

    @ApiOperation("通过表单code获取表单项列表")
    @GetMapping(value = "/getFormItemByFormCode/{formType}/{formCode}", produces = "application/json")
    public ReturnVo<List> getFormItemByFormCode(@PathVariable Integer formType, @PathVariable String formCode) {
        ReturnVo<List> returnVo = new ReturnVo<>(ReturnCode.SUCCESS, "OK");
        //TODO 查询自己数据库对应的数据返回
        String jsonStr = this.getJsonByName("form", "formItemTree.json");
        List dataList = FastJsonUtils.jsonToList(jsonStr, JSONObject.class);
        returnVo.setData(dataList);
        return returnVo;
    }

    @ApiOperation("通过节点id获取表单项显示列表")
    @PostMapping(value = "/getFormItemShowsByActivityId", produces = "application/json")
    public ReturnVo<List> getFormItemShowsByActivityId(@RequestBody JSONObject params) {
        ReturnVo<List> returnVo = new ReturnVo<>(ReturnCode.SUCCESS, "OK");
        //TODO 查询自己数据库对应的数据返回
        String jsonStr = this.getJsonByName("form", "formItemShowsTree.json");
        List dataList = FastJsonUtils.jsonToList(jsonStr, JSONObject.class);
        returnVo.setData(dataList);
        return returnVo;
    }
}
